package src.queue;

import src.mLinkedList;

/**
 * @author Dream
 */
public class LinkedListQueue<E> {
    private final src.mLinkedList<E> mLinkedList = new mLinkedList<>();
    private int size;

    /**
     * 插入
     */
    public void add(E item) {
        mLinkedList.addToRear(item);
        size++;
    }


    /**
     * 移除头部元素
     */
    public E remove() {
        if (isEmpty()) {
            System.out.println("无元素");
            return null;
        }
        try {
            E e = mLinkedList.delTopNode();
            size--;
            return e;
        } catch (Exception e) {
            System.out.println("移除失败");
        }
        return null;

    }

    /**
     * 获取头部元素
     */
    public E peek() {
        if (isEmpty()) {
            System.out.println("无元素");
            return null;
        }
        E e = mLinkedList.inquiryTopNode();
        return e;
    }

    public int size() {
        return size;
    }

    public boolean isEmpty() {
        if (size == 0) {
            return true;
        }
        return false;
    }

}
